package com.youme.model

import com.google.gson.annotations.SerializedName
import org.json.JSONObject

/**
 * Time:3/20/21 4:49 PM
 * Author:
 * Description:
 */
data class Rest(
    @SerializedName("restId") val restId: String,
    @SerializedName("restName") val restName: String,
    @SerializedName("restPic") val restPic: String,
    @SerializedName("longitude") val longitude: String,
    @SerializedName("latitude") val latitude: String,
    @SerializedName("popularity") val popularity: Int,
    @SerializedName("userStar") val userStar: Int,
    @SerializedName("order") val order: Int,
    @SerializedName("distance") val distance: String,
    @SerializedName("hallNum") val hallNum: String? = "",
    @SerializedName("parkingNum") val parkingNum: Int,
    @SerializedName("parkingPic") val parkingPic: String? = "",
    @SerializedName("parkingVideo") val parkingVideo: String? = "",
    @SerializedName("restVideo") val restVideo: String? = "",
    @SerializedName("roomNum") val roomNum: Int,
    @SerializedName("tableNum") val tableNum: Int,
    @SerializedName("userPrice") val userPrice: Int
) {
    fun getRestPicEntity(): List<RestMediaInfo> {
        return getRestMediaList(restPic)
    }

    fun getParkingPicEntity(): List<RestMediaInfo> {
        return getRestMediaList(parkingPic)
    }

    fun getParkingVideoEntity(): List<RestMediaInfo> {
        return getRestMediaList(parkingVideo)
    }

    fun getRestVideoEntity(): List<RestMediaInfo> {
        return getRestMediaList(restPic)
    }
}

class RestMediaInfo(
    @SerializedName("name") val name: String,
    @SerializedName("url") val url: String,
    @SerializedName("uid") val uid: String,
    @SerializedName("status") val status: String
)

data class Product(
    val categoryName: String,
    val categoryType: String,
    val foods: List<Food>
)

data class Room(
    val id: String,
    val deptId: String,
    val type: Int,
    val deskPic: String,
    val remark: String,
    val roomName: String,
    val deskNum: Int,
    val deptName: String
)

data class FoodAdd(
    @SerializedName("id") val id: String,
    @SerializedName("deskId") val deskId: String,
    @SerializedName("productId") val productId: String,
    @SerializedName("productName") val productName: String,
    @SerializedName("productPrice") val productPrice: Double,
    @SerializedName("productQuantity") var productQuantity: Int
)

data class Food(
    @SerializedName("categoryId") val categoryId: String,
    @SerializedName("description") val description: String?,
    @SerializedName("icon") val icon: String,
    @SerializedName("name") val name: String,
    @SerializedName("oriPrice") val oriPrice: String,
    @SerializedName("popularity") val popularity: Int,
    @SerializedName("price") val price: Double,
    @SerializedName("productId") val productId: String,
    @SerializedName("categoryName") val categoryName: String,
    @SerializedName("restName") val restName: String,
    @SerializedName("restId") val restId: String,
    @SerializedName("saleNum") val saleNum: String,
    @SerializedName("takeOut") val takeOut: Int,
    @SerializedName("stock") val stock: Int
) {
    fun getIconEntity(): List<RestMediaInfo> {
        return getRestMediaList(icon)
    }
}

data class ProductDetail(
    val rest: Rest,
    val product: List<Product>
)

fun getRestMediaList(json: String?): List<RestMediaInfo> {
    val list = mutableListOf<RestMediaInfo>()
    json?.let {
        val root = JSONObject(json)
        list.add(
            RestMediaInfo(
                root.optString("name") ?: "",
                root.optString("url") ?: "",
                root.optString("uid") ?: "",
                root.optString("status") ?: ""
            )
        )
    }
    return list
}
